<style>
	@media (min-width: 1000px){
		.login-window-container .weui-cells {
			margin-top: 100px;
		}
		.login-window-container {
			border-radius: 5px;
			width: 300px;
			border: 1px solid #ccc;
			padding: 20px;
			margin-right: 50px;
			height: 400px;
		}
	}

</style>
<div id='login-sms' class='weui-cells'>
	<div class='weui-cell bc-input-focus1'>
		<div class='weui-cell__hd' style='width:70px;'>手机号码</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-sms-send').trigger('click')"><input id="login-sms-tel" type='tel' class='weui-input' name='account' placeholder="输入手机号码" /></form></div>
		<div class='weui-cell__ft'><button id="login-sms-send" style='margin-top: 0px;' class='weui-btn weui-btn_mini weui-btn_default'>发送</button></div>

	</div>
	<div class='weui-cell bc-input-focus1' style='display: none;' id="login-sms-vcode-cell">
		<div class='weui-cell__hd' style='width:70px;'>图形码</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-sms-send').trigger('click')"><input type='email' id="login-sms-vcode" class='login-vcode-input weui-input' name='vcode' placeholder="输入图形码" /></form></div>
		<div class='weui-cell__ft'><img class='vcode'/></div>
	</div>
	<div class='weui-cell bc-input-focus1'>
		<div class='weui-cell__hd' style='width:70px;'>验证码</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-sms-check').trigger('click')"><input id="login-sms-code" type='tel' class='weui-input' name='password' placeholder="验证码" /></form></div>

	</div>
	<div class='weui-cell bc-input-focus1'>
		<div class='weui-cell__hd' style='width:70px;'>密码</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-sms-check').trigger('click')"><input id="password" type='password' class='weui-input' name='password' placeholder="请输入密码" /></form></div>
	</div>
	<div class='weui-cell bc-input-focus1'>
		<div class='weui-cell__hd' style='width:70px;'>确认密码</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-sms-check').trigger('click')"><input id="passwordx" type='password' class='weui-input' name='passwordx' placeholder="确认密码" /></form></div>
	</div>
	<div class='weui-cell bc-input-focus1' id="introduce2">
		<div class='weui-cell__hd' style='width:70px;'>推荐人</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-sms-check').trigger('click')"><input id="introduce" type='tel' class='weui-input' name='introduce' placeholder="推荐人会员号" /></form></div>
	</div>
	<!--<label class="weui-cell weui-check__label login-auto">-->
	<!--<div class="weui-cell__hd">-->
	<!--<input checked="checked" id="login-sms-auto" type="checkbox" class="weui-check" name="auto">-->
	<!--<i class="weui-icon weui-icon-checked"></i>-->
	<!--</div>-->
	<!--<div class="weui-cell__bd">-->
	<!--<small>自动登录</small>-->
	<!--</div>-->
	<!--</label>-->
</div>
<div class='errormsg'></div>
<div class='weui-btn-area'>
	<button id="login-sms-check" class='weui-btn weui-btn_disabled weui-btn_primary'>验证短信</button>
</div>
<script>
    login_sms = function(){
        var tel,tel_reg = /^1\d{10}$/,code;
        var password_reg = /((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}$/;
        POST.init("#login-sms-send",{
            stop:function(){
                if($("#login-sms-send").hasClass("weui-btn_disabled")) return true;
                var tel_input = $("#login-sms-tel");
                tel = tel_input.val();
                if(!tel_reg.test(tel)){
                    var errormsg = langIsZh?"请输入正确的手机号码":"phone number incorrect";
                    var action = langIsZh?"发送":"send";
                    alert(errormsg)
                    tel_input.focus();
                    return true;
                }
            },
            url:"/login/sms_send",
            input:function(){
                var vcode = $("#login-sms-vcode").val();
                var auto = $("#login-sms-auto").prop("checked")?1:0;
                return {tel:tel,vcode:vcode,auto:auto}
            },
            success:function(e,res){
                var c = $("#login-sms-check");
                var s = $("#login-sms-send");
                TIMER.start(s,res.data.remain);
                c.removeClass('weui-btn_disabled');
                $("#login-sms-vcode-cell").hide();
                $("#login-sms-code").focus()
            },
            msg:{
                "vcode error":"图形码不正确",
                "token cooling":"请稍后再发送",
                "token too much":"尝试太多，请重新发送短信",
                "tel exist":"号码已被使用",
            },
            text:langIsZh?"发送":"send",
            error:function(e,res){
                switch(res.errormsg){
                    case "vcode error":
                        $("#login-sms-vcode-cell").show();
                        $(".vcode").addClass("active")
                        $(".vcode").attr('src','/vcode')
                        $("#login-sms-vcode").val('')
                        $("#login-sms-vcode").focus();
                        break;
                    default:
                        $("#login-sms-tel").focus();
                        $("#login-sms-vcode-cell").hide();
                        break;
                }
                var remain = res.data
                if(remain) remain = remain.remain;
                if(remain) TIMER.start($("#login-sms-send"),remain);
            }
        })
        POST.init("#login-sms-check",{
            stop:function(){
                if($("#login-sms-check").hasClass("weui-btn_disabled")) return true;
                var tel_input = $("#login-sms-tel");
                tel = tel_input.val();
                if(!tel_reg.test(tel)){
                    var errormsg = langIsZh?"请输入正确的手机号码":"phone number incorrect";
                    var action = langIsZh?"发送":"send";
                    alert(errormsg)
                    tel_input.focus();
                    return true
                }
                var code_input = $("#login-sms-code");
                code = code_input.val();
                if(!code){
                    var errormsg = langIsZh?"请输入验证码":"code incorrect";
                    var action = langIsZh?"验证":"identify";
                    alert(errormsg)
                    code_input.focus();
                    return true
                }
                var password = $("#password").val();
                var passwordx = $("#passwordx").val();
                if(!password_reg.test(password)){
                    var errormsg = '请输入正确的密码(大小写字母+数字8-16位的组合)';
                    err.html(errormsg);
                    alert(errormsg,' ',1);
                    p.focus();
                    return true;
                }
                if(!password){
                    alert('密码不能为空')
                    tel_input.focus();
                    return true;
                }
                if(!passwordx){
                    alert('请确认密码')
                    tel_input.focus();
                    return true;
                }
                if(password !== passwordx){
                    alert('两次密码不一致')
                    tel_input.focus();
                    return true;
                }
            },
            input:function(){
                var introduce = $("#introduce").val();
                var password = $("#password").val();
                var passwordx = $("#passwordx").val();
                return {tel:tel,code:code,introduce:introduce,password:password,passwordx:passwordx}
            },
            url:"/login/sms_check",
            text:langIsZh?"验证":"identify",
            success:function(e,res){
                $('#login-tel input').val('');
                $(document).trigger('login-success');
                $(document).trigger('login-success-tel');
                if(typeof res.bind){
                    location.replace("http://api.hongyanche.com/home#bind_wechat");
                    location.reload();
                }
            },
            msg:{
                "code error":"验证码不正确"
            }
        })
    }
    $(function(){
        login_sms();
    })
</script>